package com.example.bookmanagementsystem.config;

import com.example.bookmanagementsystem.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.Arrays;
import java.util.List;

@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Autowired
    //自定义的拦截器对象
    private LoginInterceptor loginInterceptor;
    private static final List<String> excludePath = Arrays.asList(
            "/user/login",
            "/**/*.html", //排除前端静态资源
            "/**/*.css",
            "/**/*.js",
            "/**/*.png",
            "/test/**"
    );

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //注册自定义拦截器对象
        registry.addInterceptor(loginInterceptor)
                //设置拦截器拦截的请求路径
                //表示给所有方法添加拦截器
                .addPathPatterns("/**")
                .excludePathPatterns(excludePath);
    }
}
